﻿/*!
 * \file dubbo_serialize_hessian2.c
 *
 * \brief 共通定义
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 * 共通使用的宏和结构体
 *
 * \version 1.0
 * \author jikw
 * \date 2016/12/10
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "frsutl.h"
#include "frhash2.h"
#include "frct_comm.h"
#include "frservice_comm.h"
#include "frct_detect_hash.h"
#include "frvar_field.h"
#include "dubbo_serialize_hessian2.h"

union int64_double_bits {
    int64_t int_bits;
    double double_bits;
};

/*!
 * 链表查找规则
 *
 * \Frlist_node *p_st_node
 * \const void *p_compare_data
 *
 * \return int
 *
 * \note
 *
 */
FR_STATIC int __fields_list_node_find(Frlist_node *p_st_node, const void *p_compare_data)
{
    if (p_st_node == NULL)
        return 1;

    if (((dubbo_fields_list *)(p_st_node->data))->i_count == *((int*)p_compare_data))
        return 0;
    else
        return 1;
}

/*!
 * 链表节点释放规则
 *
 * \Frlist_node *p_st_node
 *
 * \return void
 *
 * \note
 *
 */
void fields_list_node_free(Frlist_node *p_st_node)
{
    dubbo_fields_list *p_st_info = NULL;

    if (p_st_node==NULL || p_st_node->data == NULL )
        return;

    p_st_info = (dubbo_fields_list *)FRLIST_GET_NODE_DATA(p_st_node);

    if (p_st_info->p_fields_name)
        frfree(p_st_info->p_fields_name);

    if (p_st_info->p_fields_value)
        frfree(p_st_info->p_fields_value);

    frfree(p_st_info);
    return;
}

/*!
 * serialize_hessian2_writestring
 *
 * \param p_packet        (resp数据)
 * \param p_st_body_data
 * \param p_name          (上报指标项名字)
 *
 * \return FR_SUCC   成功\n
 *         FR_FAIL   失败
 *
 * \note
 *
 */
int serialize_hessian2_writestring(Frbyte_Packet *p_packet, Frreport_body_data *p_st_body_data, char *p_name)
{
    int i_ret = 0;
    int i_value_len = 0;
    uint8_t u8_len = 0;
    uint8_t u8_len_temp = 0;
    uint32_t u32_len = 0;
    uint32_t u32_len_temp = 0;
    char *p_value = NULL;

    if (p_packet == NULL || p_st_body_data == NULL || p_name == NULL)
        return FR_FAIL;

    if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
        return FR_FAIL;
    if (u8_len == 'N')//值为空
    {
        i_ret = frreport_body_l7_add_str(p_st_body_data, p_name, "NULL");
        if (i_ret == FR_FAIL)
            return FR_FAIL;
    }
    else if (u8_len <= '\x1f')
    {
        i_value_len = (int)u8_len;
        if (i_value_len == 0)
        {
            if (frreport_body_l7_add_str(p_st_body_data, p_name, "NULL") == FR_FAIL)
                goto ERROR;
            return FR_SUCC;
        }
        p_value = (char *)frmalloc(i_value_len+1);
        if (p_value == NULL)
            goto ERROR;
        memset(p_value, 0x00, i_value_len+1);
        if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
            goto ERROR;
        if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
            goto ERROR;
        frfree(p_value);
    }
    else if (u8_len >= '\x30' && u8_len <= '\x33')
    {
        if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
            goto ERROR;
        i_value_len = ((int)u8_len-48)*256 + u8_len_temp;

        p_value = (char *)frmalloc(i_value_len+1);
        if (p_value == NULL)
            goto ERROR;
        memset(p_value, 0x00, i_value_len+1);
        if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
            goto ERROR;
        if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
            goto ERROR;
        frfree(p_value);
    }
    else if (u8_len == 'S')
    {
        if (bytebuff_get_int(p_packet, 1, &u32_len, BYTE_BIG_ENDIAN) == FR_FAIL)
            goto ERROR;
        if (bytebuff_get_int(p_packet, 1, &u32_len_temp, BYTE_BIG_ENDIAN) == FR_FAIL)
            goto ERROR;
        i_value_len = (int)u32_len*256 + u32_len_temp;

        p_value = (char *)frmalloc(i_value_len+1);
        if (p_value == NULL)
            goto ERROR;
        memset(p_value, 0x00, i_value_len+1);
        if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
            goto ERROR;
        if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
            goto ERROR;
        frfree(p_value);
    }
    //暂不考虑长度大于0x8000的情况
    else
        return FR_FAIL;

    return FR_SUCC;

ERROR:
    if (p_value)
        frfree(p_value);
    return FR_FAIL;
}

/*!
 * __serialize_hessian2_readint
 *
 * \param p_packet
 * \param p_i_value
 *
 * \return FR_SUCC   成功\n
 *         FR_FAIL   失败
 *
 * \note
 *
 */
FR_STATIC int __serialize_hessian2_readint(Frbyte_Packet *p_packet, int *p_i_value)
{
    uint8_t u8_len = 0;
    uint8_t u8_len_temp = 0;
    uint8_t u8_len_temp_ = 0;
    uint32_t u32_int = 0;
    uint64_t u64_long = 0;

    if (p_packet == NULL || p_i_value == NULL)
        return FR_FAIL;

    if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
        return FR_FAIL;

    switch (u8_len)
    {
        case 'N':
            *p_i_value = 0;
            break;

        case 'F':
            *p_i_value = 0;
            break;

        case 'T':
            *p_i_value = 1;
            break;

        // direct integer
        case 0x80: case 0x81: case 0x82: case 0x83:
        case 0x84: case 0x85: case 0x86: case 0x87:
        case 0x88: case 0x89: case 0x8a: case 0x8b:
        case 0x8c: case 0x8d: case 0x8e: case 0x8f:
        case 0x90: case 0x91: case 0x92: case 0x93:
        case 0x94: case 0x95: case 0x96: case 0x97:
        case 0x98: case 0x99: case 0x9a: case 0x9b:
        case 0x9c: case 0x9d: case 0x9e: case 0x9f:
        case 0xa0: case 0xa1: case 0xa2: case 0xa3:
        case 0xa4: case 0xa5: case 0xa6: case 0xa7:
        case 0xa8: case 0xa9: case 0xaa: case 0xab:
        case 0xac: case 0xad: case 0xae: case 0xaf:
        case 0xb0: case 0xb1: case 0xb2: case 0xb3:
        case 0xb4: case 0xb5: case 0xb6: case 0xb7:
        case 0xb8: case 0xb9: case 0xba: case 0xbb:
        case 0xbc: case 0xbd: case 0xbe: case 0xbf:
            *p_i_value = u8_len - 0x90;
            break;

        //byte int
        case 0xc0: case 0xc1: case 0xc2: case 0xc3:
        case 0xc4: case 0xc5: case 0xc6: case 0xc7:
        case 0xc8: case 0xc9: case 0xca: case 0xcb:
        case 0xcc: case 0xcd: case 0xce: case 0xcf:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = ((u8_len - 0xc8) << 8) + u8_len_temp;
            break;

        //short int
        case 0xd0: case 0xd1: case 0xd2: case 0xd3:
        case 0xd4: case 0xd5: case 0xd6: case 0xd7:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = ((u8_len - 0xd4) << 16) + 256 * u8_len_temp + u8_len_temp_;
            break;

        case 'I': case 0x59:
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = u32_int;
            break;

        //direct long
        case 0xd8: case 0xd9: case 0xda: case 0xdb:
        case 0xdc: case 0xdd: case 0xde: case 0xdf:
        case 0xe0: case 0xe1: case 0xe2: case 0xe3:
        case 0xe4: case 0xe5: case 0xe6: case 0xe7:
        case 0xe8: case 0xe9: case 0xea: case 0xeb:
        case 0xec: case 0xed: case 0xee: case 0xef:
            *p_i_value = u8_len - 0xe0;
            break;

        //byte long
        case 0xf0: case 0xf1: case 0xf2: case 0xf3:
        case 0xf4: case 0xf5: case 0xf6: case 0xf7:
        case 0xf8: case 0xf9: case 0xfa: case 0xfb:
        case 0xfc: case 0xfd: case 0xfe: case 0xff:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = ((u8_len - 0xf8) << 8) + u8_len_temp;
            break;

        //short long
        case 0x38: case 0x39: case 0x3a: case 0x3b:
        case 0x3c: case 0x3d: case 0x3e: case 0x3f:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = ((u8_len - 0x3c) << 16) + 256 * u8_len_temp + u8_len_temp_;
            break;

        case 'L': case 'D':
            if (bytebuff_get_long(p_packet, 8, &u64_long, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = (int)u64_long;
            break;

        case 0x5b:
            *p_i_value = 0;
            break;

        case 0x5c:
            *p_i_value = 1;
            break;

        case 0x5d:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = u8_len_temp;
            break;

        case 0x5e:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = (short) (256 * u8_len_temp + u8_len_temp_);
            break;

        case 0x5f:
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            *p_i_value = (int) (0.001 * u32_int);
            break;

        default:
            return FR_FAIL;
    }

    return FR_SUCC;
}

 /*!
 * __serialize_hessian2_readstring
 *
 * \param p_packet
 * \param pp_data_out
 *
 * \return int
 *
 * \note pp_outbuff内存空间在该函数内部生成,需要在外部释放
 *
 */
FR_STATIC int __serialize_hessian2_readstring(Frbyte_Packet *p_packet, char **pp_data_out)
{
    int i_len = 0;
    int i_count = 0;
    int i_value_len = 0;
    long l_len = 0;
    uint8_t u8_len = 0;
    uint8_t u8_len_temp = 0;
    uint8_t u8_len_temp_ = 0;
    uint32_t u32_int = 0;
    uint64_t u64_long = 0;
    char arr_temp[ARRAY_LEN] = {0};
    char *p_value = NULL;
    union int64_double_bits u_64bits;

    if (p_packet == NULL || pp_data_out == NULL)
        return FR_FAIL;

    if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
        return FR_FAIL;

    memset(arr_temp, 0x00, sizeof(arr_temp));

    switch (u8_len)
    {
        case 'N':
            snprintf(arr_temp, sizeof(arr_temp), "%s", "NULL");
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 'T':
            snprintf(arr_temp, sizeof(arr_temp), "%s", "true");
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 'F':
            snprintf(arr_temp, sizeof(arr_temp), "%s", "false");
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //direct integer
        case 0x80: case 0x81: case 0x82: case 0x83:
        case 0x84: case 0x85: case 0x86: case 0x87:
        case 0x88: case 0x89: case 0x8a: case 0x8b:
        case 0x8c: case 0x8d: case 0x8e: case 0x8f:
        case 0x90: case 0x91: case 0x92: case 0x93:
        case 0x94: case 0x95: case 0x96: case 0x97:
        case 0x98: case 0x99: case 0x9a: case 0x9b:
        case 0x9c: case 0x9d: case 0x9e: case 0x9f:
        case 0xa0: case 0xa1: case 0xa2: case 0xa3:
        case 0xa4: case 0xa5: case 0xa6: case 0xa7:
        case 0xa8: case 0xa9: case 0xaa: case 0xab:
        case 0xac: case 0xad: case 0xae: case 0xaf:
        case 0xb0: case 0xb1: case 0xb2: case 0xb3:
        case 0xb4: case 0xb5: case 0xb6: case 0xb7:
        case 0xb8: case 0xb9: case 0xba: case 0xbb:
        case 0xbc: case 0xbd: case 0xbe: case 0xbf:
            i_len = u8_len-0x90;
            snprintf(arr_temp, sizeof(arr_temp), "%d", i_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //byte int
        case 0xc0: case 0xc1: case 0xc2: case 0xc3:
        case 0xc4: case 0xc5: case 0xc6: case 0xc7:
        case 0xc8: case 0xc9: case 0xca: case 0xcb:
        case 0xcc: case 0xcd: case 0xce: case 0xcf:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            i_len = ((u8_len-0xc8)<<8) + u8_len_temp;
            snprintf(arr_temp, sizeof(arr_temp), "%d", i_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //short int
        case 0xd0: case 0xd1: case 0xd2: case 0xd3:
        case 0xd4: case 0xd5: case 0xd6: case 0xd7:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            i_len = ((u8_len-0xd4)<<16) + 256*u8_len_temp + u8_len_temp_;
            snprintf(arr_temp, sizeof(arr_temp), "%d", i_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 'I': case 0x59:
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            snprintf(arr_temp, sizeof(arr_temp), "%d", u32_int);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //direct long
        case 0xd8: case 0xd9: case 0xda: case 0xdb:
        case 0xdc: case 0xdd: case 0xde: case 0xdf:
        case 0xe0: case 0xe1: case 0xe2: case 0xe3:
        case 0xe4: case 0xe5: case 0xe6: case 0xe7:
        case 0xe8: case 0xe9: case 0xea: case 0xeb:
        case 0xec: case 0xed: case 0xee: case 0xef:
            l_len = u8_len-0xe0;
            snprintf(arr_temp, sizeof(arr_temp), "%ld", l_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //byte long
        case 0xf0: case 0xf1: case 0xf2: case 0xf3:
        case 0xf4: case 0xf5: case 0xf6: case 0xf7:
        case 0xf8: case 0xf9: case 0xfa: case 0xfb:
        case 0xfc: case 0xfd: case 0xfe: case 0xff:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            l_len = ((u8_len-0xf8)<<8) + u8_len_temp;
            snprintf(arr_temp, sizeof(arr_temp), "%ld", l_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        //short long
        case 0x38: case 0x39: case 0x3a: case 0x3b:
        case 0x3c: case 0x3d: case 0x3e: case 0x3f:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            l_len = ((u8_len-0x3c)<<16) + 256*u8_len_temp + u8_len_temp_;
            snprintf(arr_temp, sizeof(arr_temp), "%ld", l_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 'L':
            if (bytebuff_get_long(p_packet, 8, &u64_long, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            snprintf(arr_temp, sizeof(arr_temp), "%ld", u64_long);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x5b:
            snprintf(arr_temp, sizeof(arr_temp), "%lf", (double)0.0);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x5c:
            snprintf(arr_temp, sizeof(arr_temp), "%lf", (double)1.0);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x5d:
            if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = u8_len;
            snprintf(arr_temp, sizeof(arr_temp), "%lf", u_64bits.double_bits);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x5e:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = 256*u8_len_temp + u8_len_temp_;
            snprintf(arr_temp, sizeof(arr_temp), "%lf", u_64bits.double_bits);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x5f:
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            snprintf(arr_temp, sizeof(arr_temp), "%lf", 0.001*u32_int);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 'D':
            if (bytebuff_get_long(p_packet, 8, &u64_long, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = u64_long;
            snprintf(arr_temp, sizeof(arr_temp), "%lf", u_64bits.double_bits);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        case 0x4b://BC_DATE_MINUTE
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            snprintf(arr_temp, sizeof(arr_temp), "%ld", 60000L*u32_int);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;

        case 'S': case 'R':
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            //UTF8的编码的个数
            i_value_len = (u8_len_temp << 8) + u8_len_temp_;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        //0-byte string
        case 0x00: case 0x01: case 0x02: case 0x03:
        case 0x04: case 0x05: case 0x06: case 0x07:
        case 0x08: case 0x09: case 0x0a: case 0x0b:
        case 0x0c: case 0x0d: case 0x0e: case 0x0f:
        case 0x10: case 0x11: case 0x12: case 0x13:
        case 0x14: case 0x15: case 0x16: case 0x17:
        case 0x18: case 0x19: case 0x1a: case 0x1b:
        case 0x1c: case 0x1d: case 0x1e: case 0x1f:
            //UTF8的编码的个数
            i_value_len = u8_len - 0x00;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        case 0x30: case 0x31: case 0x32: case 0x33:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                goto ERROR;
            //UTF8的编码的个数
            i_value_len = ((int)u8_len-0x30)*256 + u8_len_temp;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        case 'A': case 'B':
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            //UTF8的编码的个数
            i_value_len = (u8_len_temp << 8) + u8_len_temp_;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        case 0x20: case 0x21: case 0x22: case 0x23:
        case 0x24: case 0x25: case 0x26: case 0x27:
        case 0x28: case 0x29: case 0x2a: case 0x2b:
        case 0x2c: case 0x2d: case 0x2e: case 0x2f:
            i_value_len = (int)u8_len - 0x20;
            p_value = (char *)frmalloc(i_value_len + 1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_value_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        case 0x34: case 0x35: case 0x36: case 0x37:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                goto ERROR;
            i_value_len = (u8_len-0x34)*256 + u8_len_temp;
            p_value = (char *)frmalloc(i_value_len + 1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_value_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
                goto ERROR;
            *pp_data_out = p_value;
            break;

        case 0x51:
            if (__serialize_hessian2_readint(p_packet, &i_value_len) == FR_FAIL)
                goto ERROR;
            snprintf(arr_temp, sizeof(arr_temp), "%d", i_value_len);
            p_value = frstrdup(arr_temp);
            *pp_data_out = p_value;
            break;

        default:
            return FR_FAIL;
    }

    return FR_SUCC;

ERROR:
    if (p_value)
        frfree(p_value);
    return FR_FAIL;
}

/*!
 * __serialize_hessian2_readtype
 *
 * \param p_packet
 *
 * \return p_type
 *
 * \note
 *
 */
FR_STATIC int __serialize_hessian2_readtype(Frbyte_Packet *p_packet)
{
    int i_len = 0;
    uint8_t u8_len = 0;
    char *p_type = NULL;

    if (p_packet == NULL)
        return FR_FAIL;

    if (bytebuff_peek_char(p_packet, &u8_len) == FR_FAIL)
        return FR_FAIL;

    switch (u8_len)
    {
        case 0x00: case 0x01: case 0x02: case 0x03:
        case 0x04: case 0x05: case 0x06: case 0x07:
        case 0x08: case 0x09: case 0x0a: case 0x0b:
        case 0x0c: case 0x0d: case 0x0e: case 0x0f:
        case 0x10: case 0x11: case 0x12: case 0x13:
        case 0x14: case 0x15: case 0x16: case 0x17:
        case 0x18: case 0x19: case 0x1a: case 0x1b:
        case 0x1c: case 0x1d: case 0x1e: case 0x1f:
        case 0x30: case 0x31: case 0x32: case 0x33:
        case 'R': case 'S':
            __serialize_hessian2_readstring(p_packet, &p_type);
            if (p_type)
                frfree(p_type);
            break;

        default:
            if (__serialize_hessian2_readint(p_packet, &i_len) == FR_FAIL)
                return FR_FAIL;
            break;
    }

    return FR_SUCC;
}

/*!
 * serialize_hessian2_readobject
 *
 * \param p_packet
 * \param p_st_body_data
 * \param p_st_private
 * \param p_name          ("request.rpc.arg.%d"或"response.rpc.return.%d")
 *
 * \return FR_FAIL        失败\n
 *         FR_SUCC        成功
 *
 * \note
 *
 */
int serialize_hessian2_readobject(Frbyte_Packet *p_packet, L7session_dubbo_private *p_st_private, Frreport_body_data *p_st_body_data, char *p_name)
{
    int i_ret = 0;
    int i_len = 0;
    int i_temp_ = 0;
    int i_temp = 0;
    int i_count = 0;
    int i_value_len = 0;
    uint8_t u8_len = 0;
    uint8_t u8_len_temp = 0;
    uint8_t u8_len_temp_ = 0;
    uint32_t u32_int = 0;
    uint64_t u64_long = 0;
    char *p_value = NULL;
    char *p_map_key = NULL;
    char arr_name[ARRAY_LEN] = {0};
    char arr_temp[ARRAY_LEN] = {0};

    Frlist_node *p_st_node = NULL;
    Frlist_node *p_st_gotnode = NULL;
    dubbo_fields_list *p_st_fields = NULL;
    union int64_double_bits u_64bits;

    if (p_packet == NULL || p_st_private == NULL || p_st_body_data == NULL ||  p_name == NULL)
        return FR_FAIL;

    memset(arr_name, 0x00, sizeof(arr_name));
    memset(arr_temp, 0x00, sizeof(arr_temp));

    if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
        return FR_FAIL;

    switch (u8_len)
    {
        case 'N'://NULL
            if (frreport_body_l7_add_str(p_st_body_data, p_name, "NULL") == FR_FAIL)
                return FR_FAIL;
            break;

        case 'T'://bool
            if (frreport_body_l7_add_str(p_st_body_data, p_name, "true") == FR_FAIL)
                return FR_FAIL;
            break;

        case 'F'://bool
            if (frreport_body_l7_add_str(p_st_body_data, p_name, "false") == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x80: case 0x81: case 0x82: case 0x83:
        case 0x84: case 0x85: case 0x86: case 0x87:
        case 0x88: case 0x89: case 0x8a: case 0x8b:
        case 0x8c: case 0x8d: case 0x8e: case 0x8f:
        case 0x90: case 0x91: case 0x92: case 0x93:
        case 0x94: case 0x95: case 0x96: case 0x97:
        case 0x98: case 0x99: case 0x9a: case 0x9b:
        case 0x9c: case 0x9d: case 0x9e: case 0x9f:
        case 0xa0: case 0xa1: case 0xa2: case 0xa3:
        case 0xa4: case 0xa5: case 0xa6: case 0xa7:
        case 0xa8: case 0xa9: case 0xaa: case 0xab:
        case 0xac: case 0xad: case 0xae: case 0xaf:
        case 0xb0: case 0xb1: case 0xb2: case 0xb3:
        case 0xb4: case 0xb5: case 0xb6: case 0xb7:
        case 0xb8: case 0xb9: case 0xba: case 0xbb:
        case 0xbc: case 0xbd: case 0xbe: case 0xbf://direct integer
            if (frreport_body_l7_add_int(p_st_body_data, p_name, u8_len-0x90) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0xc0: case 0xc1: case 0xc2: case 0xc3:
        case 0xc4: case 0xc5: case 0xc6: case 0xc7:
        case 0xc8: case 0xc9: case 0xca: case 0xcb:
        case 0xcc: case 0xcd: case 0xce: case 0xcf://byte int
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_int(p_st_body_data, p_name, ((u8_len-0xc8)<<8) + u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0xd0: case 0xd1: case 0xd2: case 0xd3:
        case 0xd4: case 0xd5: case 0xd6: case 0xd7://short int
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_int(p_st_body_data, p_name, ((u8_len-0xd4)<<16) + 256*u8_len_temp + u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            break;

        case 'I': case 0x59:
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_int(p_st_body_data, p_name, u32_int) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0xd8: case 0xd9: case 0xda: case 0xdb:
        case 0xdc: case 0xdd: case 0xde: case 0xdf:
        case 0xe0: case 0xe1: case 0xe2: case 0xe3:
        case 0xe4: case 0xe5: case 0xe6: case 0xe7:
        case 0xe8: case 0xe9: case 0xea: case 0xeb:
        case 0xec: case 0xed: case 0xee: case 0xef://direct long
            if (frreport_body_l7_add_long(p_st_body_data, p_name, u8_len-0xe0) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0xf0: case 0xf1: case 0xf2: case 0xf3:
        case 0xf4: case 0xf5: case 0xf6: case 0xf7:
        case 0xf8: case 0xf9: case 0xfa: case 0xfb:
        case 0xfc: case 0xfd: case 0xfe: case 0xff://byte long
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_long(p_st_body_data, p_name, ((u8_len-0xf8)<<8) + u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x38: case 0x39: case 0x3a: case 0x3b:
        case 0x3c: case 0x3d: case 0x3e: case 0x3f://short long
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_long(p_st_body_data, p_name, ((u8_len-0x3c)<<16) + 256*u8_len_temp + u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            break;

        case 'L': case 0x4a://BC_DATE
            if (bytebuff_get_long(p_packet, 8, &u64_long, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_long(p_st_body_data, p_name, u64_long) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x5b://BC_DOUBLE_ZERO
            if (frreport_body_l7_add_double(p_st_body_data, p_name, 0.0) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x5c://BC_DOUBLE_ONE
            if (frreport_body_l7_add_double(p_st_body_data, p_name, 1.0) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x5d://BC_DOUBLE_BYTE
            if (bytebuff_get_char(p_packet, &u8_len) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = u8_len;
            if (frreport_body_l7_add_double(p_st_body_data, p_name, u_64bits.double_bits) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x5e://BC_DOUBLE_BYTE
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = 256*u8_len_temp + u8_len_temp_;
            if (frreport_body_l7_add_double(p_st_body_data, p_name, u_64bits.double_bits) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x5f://double
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_double(p_st_body_data, p_name, 0.001*u32_int) == FR_FAIL)
                return FR_FAIL;
            break;

        case 'D':
            if (bytebuff_get_long(p_packet, 8, &u64_long, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            u_64bits.int_bits = u64_long;
            if (frreport_body_l7_add_double(p_st_body_data, p_name, u_64bits.double_bits) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x4b://BC_DATE_MINUTE
            if (bytebuff_get_int(p_packet, 4, &u32_int, BYTE_BIG_ENDIAN) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_long(p_st_body_data, p_name, 60000L*u32_int) == FR_FAIL)
                return FR_FAIL;
            break;

        case 'R': case 'S'://todo
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            //UTF8的编码的个数
            i_value_len = (u8_len_temp << 8) + u8_len_temp_;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 0x00: case 0x01: case 0x02: case 0x03:
        case 0x04: case 0x05: case 0x06: case 0x07:
        case 0x08: case 0x09: case 0x0a: case 0x0b:
        case 0x0c: case 0x0d: case 0x0e: case 0x0f:
        case 0x10: case 0x11: case 0x12: case 0x13:
        case 0x14: case 0x15: case 0x16: case 0x17:
        case 0x18: case 0x19: case 0x1a: case 0x1b:
        case 0x1c: case 0x1d: case 0x1e: case 0x1f:
            //UTF8的编码的个数
            i_value_len = u8_len - 0x00;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 0x30: case 0x31: case 0x32: case 0x33:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                goto ERROR;
            //UTF8的编码的个数
            i_value_len = ((int)u8_len-0x30)*256 + u8_len_temp;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 'A': case 'B'://todo
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                return FR_FAIL;
            if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                return FR_FAIL;
            //UTF8的编码的个数
            i_value_len = (u8_len_temp << 8) + u8_len_temp_;

            for (i_count = 0; i_count < i_value_len; i_count++)
            {
                //每一个UTF8编码的长度(只有一个字节，其最高二进制值为0。多字节，从最高位开始连续的二进制值为1的个数)
                if (bytebuff_get_char(p_packet, &u8_len_temp_) == FR_FAIL)
                    goto ERROR;

                if (u8_len_temp_ < 0x80)//0xxx xxxx 1字节
                    i_len += 1;
                else if (u8_len_temp_ >= 0xc0 && u8_len_temp_ < 0xe0)//110x xxxx 2字节
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    i_len += 2;
                }
                else if (u8_len_temp_ >= 0xe0 && u8_len_temp_ < 0xf0)//1110 xxxx 3字节
                {
                    if (bytebuff_skip(p_packet, 2) != FR_SUCC)
                        goto ERROR;
                    i_len += 3;
                }
                else if (u8_len_temp_ >= 0xf0 && u8_len_temp_ < 0xf8)//1111 0xxx 4字节
                {
                    if (bytebuff_skip(p_packet, 3) != FR_SUCC)
                        goto ERROR;
                    i_len += 4;
                }
                else if (u8_len_temp_ >= 0xf8 && u8_len_temp_ < 0xfc)//1111 10xx 5字节
                {
                    if (bytebuff_skip(p_packet, 4) != FR_SUCC)
                        goto ERROR;
                    i_len += 5;
                }
                else if (u8_len_temp_ >= 0xfc && u8_len_temp_ < 0xfe)//1111 110x 6字节
                {
                    if (bytebuff_skip(p_packet, 5) != FR_SUCC)
                        goto ERROR;
                    i_len += 6;
                }
                else
                    goto ERROR;
            }

            if (bytebuffer_backspace(p_packet, i_len) != FR_SUCC)
                goto ERROR;

            p_value = (char *)frmalloc(i_len+1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_len) == FR_FAIL)
                goto ERROR;
            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 0x20: case 0x21: case 0x22: case 0x23:
        case 0x24: case 0x25: case 0x26: case 0x27:
        case 0x28: case 0x29: case 0x2a: case 0x2b:
        case 0x2c: case 0x2d: case 0x2e: case 0x2f:
            i_value_len = (int)u8_len - 0x20;
            p_value = (char *)frmalloc(i_value_len + 1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_value_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
                goto ERROR;

            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 0x34: case 0x35: case 0x36: case 0x37:
            if (bytebuff_get_char(p_packet, &u8_len_temp) == FR_FAIL)
                goto ERROR;
            i_value_len = (u8_len-0x34)*256 + u8_len_temp;
            p_value = (char *)frmalloc(i_value_len + 1);
            if (p_value == NULL)
                goto ERROR;
            memset(p_value, 0x00, i_value_len+1);
            if (bytebuff_get_bytes(p_packet, p_value, i_value_len) == FR_FAIL)
                goto ERROR;

            if (frreport_body_l7_add_str(p_st_body_data, p_name, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;
            break;

        case 0x55://BC_LIST_VARIABLE (variable length list)
            __serialize_hessian2_readtype(p_packet);
            while(1)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                if (bytebuff_peek_char(p_packet, &u8_len) == FR_FAIL)
                    goto ERROR;
                if (u8_len == 'Z')
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    break;
                }
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
                i_count += 1;
            }
            break;

        case 0x57://BC_LIST_VARIABLE_UNTYPED
            while(1)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                if (bytebuff_peek_char(p_packet, &u8_len) == FR_FAIL)
                    goto ERROR;
                if (u8_len == 'Z')
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    break;
                }
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
                i_count += 1;
            }
            break;

        case 'V'://BC_LIST_FIXED(fixed length lists)
            __serialize_hessian2_readtype(p_packet);
            if (__serialize_hessian2_readint(p_packet, &i_len) == FR_FAIL)
                goto ERROR;
            if (i_len == 0)
            {
                if (frreport_body_l7_add_str(p_st_body_data, p_name, "NULL") == FR_FAIL)
                    goto ERROR;
            }
            for (i_count = 0; i_count < i_len; i_count++)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
            }
            break;

        case 0x58://BC_LIST_FIXED_UNTYPED(fixed length lists)
            if (__serialize_hessian2_readint(p_packet, &i_len) == FR_FAIL)
                goto ERROR;
            for (i_count = 0; i_count < i_len; i_count++)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
            }
            break;

        case 0x70: case 0x71: case 0x72: case 0x73:
        case 0x74: case 0x75: case 0x76: case 0x77://compact fixed list(fixed length lists)
            __serialize_hessian2_readtype(p_packet);
            i_len = u8_len - 0x70;
            if (i_len == 0)
            {
                if (frreport_body_l7_add_str(p_st_body_data, p_name, "NULL") == FR_FAIL)
                    goto ERROR;
            }
            for (i_count = 0; i_count < i_len; i_count++)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
            }
            break;

        case 0x78: case 0x79: case 0x7a: case 0x7b:
        case 0x7c: case 0x7d: case 0x7e: case 0x7f://compact fixed untyped list(fixed length lists)
            i_len = u8_len - 0x78;
            for (i_count = 0; i_count < i_len; i_count++)
            {
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.list.%d", p_name, i_count+1);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;
            }
            break;

        case 'H'://map
            while(1)
            {
                if (bytebuff_peek_char(p_packet, &u8_len_temp) == FR_FAIL)
                    goto ERROR;
                if (u8_len_temp == 'Z')
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    break;
                }
                __serialize_hessian2_readstring(p_packet, &p_map_key);
                if (p_map_key == NULL)
                    goto ERROR;
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.fields.%s", p_name, p_map_key);

                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;

                frfree(p_map_key);
                p_map_key = NULL;
            }
            break;

        case 'M':
            __serialize_hessian2_readtype(p_packet);
            while(1)
            {
                if (bytebuff_peek_char(p_packet, &u8_len_temp) == FR_FAIL)
                    goto ERROR;
                if (u8_len_temp == 'Z')
                {
                    if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                        goto ERROR;
                    break;
                }
                __serialize_hessian2_readstring(p_packet, &p_map_key);
                if (p_map_key == NULL)
                    goto ERROR;
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.fields.%s", p_name, p_map_key);

                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                    goto ERROR;

                frfree(p_map_key);
                p_map_key = NULL;
            }
            break;

        case 'C':
            //取type
            __serialize_hessian2_readstring(p_packet, &p_value);
            if (p_value == NULL)
                goto ERROR;
            snprintf(arr_temp, sizeof(arr_temp), "%s.type", p_name);
            if (frreport_body_l7_add_str(p_st_body_data, arr_temp, p_value) == FR_FAIL)
                goto ERROR;
            frfree(p_value);
            p_value = NULL;

            //取个数
            if (__serialize_hessian2_readint(p_packet, &i_value_len) == FR_FAIL)
                goto ERROR;
            p_st_private->i_len = i_value_len;

            //创建链表
            if (p_st_private->p_fields_list_dubbo == NULL)
                p_st_private->p_fields_list_dubbo = frlist_create();
            if (p_st_private->p_fields_list_dubbo == NULL)
                goto ERROR;

            //取fields_name添加到链表
            for (i_temp = 0; i_temp < i_value_len; i_temp++)
            {
               //把序号和name存进链表
                p_st_fields = (dubbo_fields_list *)frmalloc(sizeof(dubbo_fields_list));
                memset(p_st_fields, 0x00, sizeof(dubbo_fields_list));

                __serialize_hessian2_readstring(p_packet, &p_st_fields->p_fields_name);
                if (p_st_fields->p_fields_name == NULL)
                {
                    frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
                    p_st_private->p_fields_list_dubbo = NULL;
                    goto ERROR;
                }
                p_st_fields->i_count = i_temp+1;

                p_st_node = frlist_node_create(p_st_fields);
                frlist_add_header(p_st_private->p_fields_list_dubbo, p_st_node);

                p_st_fields = NULL;
                p_st_node = NULL;
            }

            if (bytebuff_skip(p_packet, 1) != FR_SUCC)
                goto ERROR;

            //循环取fields_value 取一个上报一个
            for (i_temp = 0; i_temp < i_value_len; i_temp++)
            {
                //链表找key 组成名字
                i_temp_ = i_temp+1;
                p_st_gotnode = frlist_find(p_st_private->p_fields_list_dubbo, &i_temp_, __fields_list_node_find);
                if (p_st_gotnode == NULL)
                {
                    frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
                    p_st_private->p_fields_list_dubbo = NULL;
                    goto ERROR;
                }
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.fields.%s", p_name, ((dubbo_fields_list *)(p_st_gotnode->data))->p_fields_name);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                {
                    frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
                    p_st_private->p_fields_list_dubbo = NULL;
                    goto ERROR;
                }
            }
            break;

        case 0x51:
            if (__serialize_hessian2_readint(p_packet, &i_value_len) == FR_FAIL)
                return FR_FAIL;
            if (frreport_body_l7_add_int(p_st_body_data, p_name, i_value_len) == FR_FAIL)
                return FR_FAIL;
            break;

        case 0x60: case 0x61: case 0x62: case 0x63:
        case 0x64: case 0x65: case 0x66: case 0x67:
        case 0x68: case 0x69: case 0x6a: case 0x6b:
        case 0x6c: case 0x6d: case 0x6e: case 0x6f:
            //循环取fields_value 取一个上报一个
            for (i_temp = 0; i_temp < p_st_private->i_len; i_temp++)
            {
                //链表找key 组成名字
                i_temp_ = i_temp+1;
                p_st_gotnode = frlist_find(p_st_private->p_fields_list_dubbo, &i_temp_, __fields_list_node_find);
                if (p_st_gotnode == NULL)
                {
                    frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
                    p_st_private->p_fields_list_dubbo = NULL;
                    return FR_FAIL;
                }
                memset(arr_name, 0x00, sizeof(arr_name));
                snprintf(arr_name, sizeof(arr_name), "%s.fields.%s", p_name, ((dubbo_fields_list *)(p_st_gotnode->data))->p_fields_name);
                i_ret = serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
                if (i_ret == FR_FAIL)
                {
                    frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
                    p_st_private->p_fields_list_dubbo = NULL;
                    return FR_FAIL;
                }
            }
            break;

        default:
            return FR_FAIL;
            break;
    }

    return FR_SUCC;

ERROR:
    if (p_value)
        frfree(p_value);
    if (p_map_key)
        frfree(p_map_key);
    if (p_st_private->p_fields_list_dubbo)
        frlist_destroy(p_st_private->p_fields_list_dubbo, fields_list_node_free);
    return FR_FAIL;
}

 /*!
 * serialize_hessian2_req_body_parse
 *
 * \param p_packet        (resp数据)
 * \param p_st_private    (私有数据)
 * \param p_st_body_data
 *
 * \return APM_L7_ANALYZE_SUCC   成功\n
 *         APM_L7_ANALYZE_FAIL   失败
 *
 * \note
 *
 */
int serialize_hessian2_req_body_parse(Frbyte_Packet *p_packet
                        , L7session_dubbo_private *p_st_private
                        , Frreport_body_data *p_st_body_data)
{
    int i_ret = 0;
    int i_count = 0;
    char arr_name[ARRAY_LEN] = {0};

    if (p_packet == NULL || p_st_private == NULL || p_st_body_data == NULL)
        return APM_L7_ANALYZE_FAIL;

    memset(arr_name, 0x00, sizeof(arr_name));

    //取dubbo版本"request.rpc.version"
    i_ret = serialize_hessian2_writestring(p_packet, p_st_body_data, (char *)"request.rpc.dubbo.version");
    if (i_ret == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    //取path服务名
    i_ret = serialize_hessian2_writestring(p_packet, p_st_body_data, (char *)"request.rpc.path");
    if (i_ret == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    //取服务版本
    i_ret = serialize_hessian2_writestring(p_packet, p_st_body_data, (char *)"request.rpc.path.version");
    if (i_ret == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    //取调用服务的方法
    i_ret = serialize_hessian2_writestring(p_packet, p_st_body_data, (char *)APM_REPORT_KEY_TRANS_TITLE);
    if (i_ret == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    //取ParameterType
    i_ret = serialize_hessian2_writestring(p_packet, p_st_body_data, (char *)"request.rpc.parameter.types");
    if (i_ret == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    //循环取参数
    while(p_packet->ui_remaining > 1)
    {
        memset(arr_name, 0x00, sizeof(arr_name));
        snprintf(arr_name, sizeof(arr_name), "request.rpc.arg.%d", i_count+1);
        serialize_hessian2_readobject(p_packet, p_st_private, p_st_body_data, arr_name);
        i_count += 1;
    }

    if (frreport_body_l7_add_int(p_st_body_data, "request.rpc.arg.size", i_count-1) == FR_FAIL)
        return APM_L7_ANALYZE_FAIL;

    return APM_L7_ANALYZE_SUCC;
}